package cc.koit.hulk.web.controller;

import cc.koit.hulk.dao.entity.User;
import cc.koit.hulk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/hello")
    public String getUser(@RequestParam String userName){
        return "hello，"+userName;
    }

    @RequestMapping("/create")
    public User create(@RequestParam String displayName,@RequestParam String email){
        User user = new User();
        user.setDisplayName(displayName);
        user.setEmail(email);
        userService.create(user);
        return user;
    }

    @RequestMapping("/list")
    public List<User> getUserList(){
        return userService.listAll();
    }
}
